<?php
session_start();
include_once '../gerenciadores/AutoloadGerenciadores.php';
include_once 'function/RecuperaCadastro.php';
include_once 'function/data.php';
include_once '../gerenciadores/GerenciadorDaSmap.php';
require_once("fpdf/fpdf.php");


if(!isset($_POST['data'])){
	$tabCadastro = unserialize($_SESSION['cadastro']);
	$cadastro = recuperaCadastro($tabCadastro);
		
	echo "<DOCTYPE! hmtl>
		  <html>
			<head>
				<title></title>
				<meta charset='utf-8'>
				<meta charset='iso-8859-1'>
			
				<script src='js/jquery.min.js' type='text/javascript'></script>
				<script src='js/mascara.js' type='text/javascript'></script> 

				<!--Exibe um calendário na data para escolha -->
				<link rel='stylesheet' href='estilos/jquery-ui.css' />
				<script src='js/jquery-1.10.2.js'></script>
				<script src='js/jquery-ui-1.10.4.custom.js'></script>
				<script src='js/dataPicker.js'></script>
			</head>
			
			<form method='post' action='#'>
				<label>Data: </label><input type='text' onkeypress='formatar_mascara(this, '##/##/####')' name='data' class='data'>
				<input type='submit' value='Confirma'>
		 	</form>
		 </html>";
}else{
	
	$data = $_POST['data'];
	$pdf=new FPDF("L","pt","A4");
	
	
	
	$pdf -> AddPage();
	$pdf -> Ln(60);
	
	
	//cabeçalho
	$pdf -> Image('imagens/brasaope.png',380,2,-250);
	
	$pdf -> SetFont('arial','B',10);
	$pdf -> Cell(0,15,"SECRETARIA DE DEFESA SOCIAL",0,1,'C');
	$pdf -> Cell(0,15,"Academia Integrada de Defesa Social",0,1,'C');
	$pdf -> Cell(0,15,"Campus de Ensino Metropolitano I",0,1,'C');
	
	$pdf -> SetFont('arial','',14);
	$pdf -> Cell(0,50,"REQUISI��ES DO DIA: ".$_POST['data'],0,1,'C');
	
	
	
	//Tabela
	$pdf -> SetFont('arial','',8);
	$pdf -> Cell(50,15,"Cargo",1,0,'C');
	$pdf -> Cell(40,15,"Org�o",1,0,'C');
	$pdf -> Cell(200,15,"Nome",1,0,'C');
	$pdf -> Cell(50,15,"Turma",1,0,'C');
	$pdf -> Cell(180,15,"Material",1,0,'C');
	$pdf -> Cell(20,15,"Qtd",1,0,'C');
	$pdf -> Cell(90,15,"Periodo",1,0,'C');
	$pdf -> Cell(60,15,"Controle",1,0,'C');
	$pdf -> Cell(60,15,"Libera��o",1,1,'C');
	
	$gerSmap = new GerenciadorDaSmap();
	$tab =$gerSmap->exibeRequisicaoPorData(converteData($data));
	
	foreach ($tab as $requisicao) {
		$pdf -> SetFont('arial','',8);
		$pdf -> Cell(50,15,$requisicao->getInstrutor()->getCargo(),1,0,'L');
		$pdf -> Cell(40,15,$requisicao->getInstrutor()->getInstituicao(),1,0,'L');
		$pdf -> Cell(200,15,$requisicao->getInstrutor()->getNome(),1,0,'L');
		$pdf -> Cell(50,15,$requisicao->getTurma(),1,0,'C');
		$pdf -> Cell(180,15,$requisicao->getMaterial()->getDescricao(),1,0,'L');
		$pdf -> Cell(20,15,$requisicao->getMaterial()->getQuantidade(),1,0,'C');
		switch ($requisicao->getTurno()){
			case 11: $pdf -> Cell(90,15,"Manh� - 1� Hor�rio",1,0,'L');
			break;
			
			case 12: $pdf -> Cell(90,15,"Manh� - 2� Hor�rio",1,0,'L');
			break;
			
			case 21: $pdf -> Cell(90,15,"Tarde - 1� Hor�rio",1,0,'L');
			break;
			
			case 22: $pdf -> Cell(90,15,"Tarde - 2� Hor�rio",1,0,'L');
			break;
			
			case 31: $pdf -> Cell(90,15,"Noite - 1� Hor�rio",1,0,'L');
			break;
			
			case 32: $pdf -> Cell(90,15,"Noite - 2� Hor�rio",1,0,'L');
			break;
		}
		
		$pdf -> Cell(60,15,$requisicao->getControle(),1,0,'L');
	
		if($requisicao->getLiberacao()==1) {
			$pdf -> Cell(60,15,"Sim",1,1,'C');
		}else {
			$pdf -> Cell(60,15,"N�o",1,1,'C');
		}
	}
	
	date_default_timezone_set("America/Recife");
	$dia = date("d");
	$mes = date("m");
	$ano = date("Y");
	
	switch($mes) {
		case 01: $mes = "Janeiro"; Break;
		case 02: $mes = "Fevereiro"; Break;
		case 03: $mes = "Mar�o";Break;
		case 04: $mes = "Abril"; Break;
		case 05: $mes = "Maio"; Break;
		case 06: $mes = "Junho"; Break;
		case 07: $mes = "Julho"; Break;
		case 08: $mes = "Agosto"; Break;
		case 09: $mes = "Setembro"; Break;
		case 10: $mes = "Outubro"; Break;
		case 11: $mes = "Novembro"; Break;
		case 12: $mes = "Dezembro"; Break;
	}
	
	$pdf -> SetFont('arial','',10);
	$pdf -> Cell(0,60, "Jaboat�o dos Guararapes - PE, ".$dia." de ".$mes." de ".$ano,0,1,'C');
	$pdf -> Cell(0,10,"___________________________________________",0,1,'C');
	$pdf -> Cell(0,30,"Respons�vel pelo SMAP",0,1,'C');
	
	
	
	
	
	$pdf -> Output("Requisicao_de_material_$data".".pdf","I");
	
		
}